package cn.edu.sdjzu.xg.eagle.exception;

/**
 * @author STG
 * @project xg22
 * @date 2024/3/27
 * 由于Factory需要声明BaseException，如果本类扩展Exception类，会导致
 */

public class BaseException extends RuntimeException{
    private static final long serialVersionUID = 1L;

    /**
     * 所属模块
     */
    private final String module;

    /**
     * 错误码
     */
    private final String code;

    /**
     * 错误码对应的参数
     */
    private final Object[] args;

    /**
     * 错误消息
     */
    private final String defaultMessage;

    /**
     * 错误
     */
    private final Exception e;



    public BaseException(String module, String code, Object[] args, String defaultMessage, Exception e) {
        super(defaultMessage);
        this.module = module;
        this.code = code;
        this.args = args;
        this.defaultMessage = defaultMessage;
        this.e = e;
    }



    public BaseException(String module, String code, Object[] args)
    {
        this(module, code, args, null, null);
    }

    public BaseException(String module, Exception e)
    {
        this(module, null, null, null, e);
    }

    public BaseException(String module, String defaultMessage)
    {
        this(module, null, null, defaultMessage, null);
    }

    public BaseException(String code, Object[] args)
    {
        this(null, code, args, null, null);
    }

    public BaseException(String defaultMessage)
    {
        this(null, null, null, defaultMessage, null);
    }

    @Override
    public String getMessage() {
        String message = null;
        message = defaultMessage;
        return message;
    }

    public String getModule()
    {
        return module;
    }

    public String getCode()
    {
        return code;
    }

    public Object[] getArgs()
    {
        return args;
    }

    public String getDefaultMessage()
    {
        return defaultMessage;
    }

}
